package testLayer;

import static org.junit.Assert.*;
import modelLayer.Subject;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import dbLayer.DBSubject;
import dbLayer.DBTeacher;

public class SubjectDatabaseTest {
	
	private DBSubject dbSubject;
	private boolean retrieveAssociation = false;
	
	@Before
	public void setUp() throws Exception {
		
		this.dbSubject = new DBSubject();
//		this.insert();
		
	}
	
	@After
	public void tearDown() throws Exception {
		
		this.remove();
		this.dbSubject = null;
		
	}
	
	public void insert() throws Exception {
		
	//	assertTrue(this.dbSubject.insert("Sport", "blank", new DBTeacher().findById(1)) > 0);
		
	}
	
	@Test
	public void find() throws Exception {
		
//		if (retrieveAssociation) {
//			assertNotNull(this.dbSubject.find("Sport", retrieveAssociation).getTeacher());
//		}
//		else {
//			assertNotNull(this.dbSubject.find("Sport", retrieveAssociation));
//		}		
		
	}
	
	@Test
	public void findById() throws Exception {
		
//		if (retrieveAssociation) {
//			assertNotNull(this.dbSubject.findById(this.dbSubject.find("Sport", false).getId(),
//									  			  retrieveAssociation).getTeacher());
//		}
//		else {
//			assertNotNull(this.dbSubject.findById(this.dbSubject.find("Sport", false).getId(),
//											      retrieveAssociation));
//		}
//		
	}

	@Test
	public void getAll() throws Exception {
		
		boolean test = true;
		if (retrieveAssociation) {			
			for (Subject s : this.dbSubject.getAll(retrieveAssociation)) {
				if (s.getTeachers() == null) {
					test = false;
				}
			}
		}
		else {
			if (this.dbSubject.getAll(retrieveAssociation).isEmpty() &&
				!(this.dbSubject.getAll(retrieveAssociation).size() >= 1)) {
				test = true;
			}
		}
		assertTrue(test);
//		
	}
	
	@Test
	public void update() throws Exception {
		
		assertTrue(this.dbSubject.update(this.dbSubject.find("Sport", false).getId(),
										 "Sport",
								  		 "blank") > 0);

	}
	
	public void remove() throws Exception {
		
		//assertTrue(this.dbSubject.remove("Sport") > 0);
		
	} 

}
